package Java实训.第六天File文件和IO流;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class 资薪统计 {
    /*
     * 统计”C:\Users\gdq\OneDrive\桌面\File文件夹\task-20221125.doc“文件中
     * 不同职位的平均薪资
     */
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\gdq\\OneDrive\\桌面\\File文件夹\\task-20221125.txt"));
        FileWriter fw = new FileWriter("C:\\Users\\gdq\\OneDrive\\桌面\\File文件夹\\task.txt");
        HashMap<String, Integer> map = new HashMap<>();
        cc(br, map);
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            fw.write(entry.getKey()+": "+entry.getValue());
            fw.write("\n");
        }
        br.close();
        fw.close();
    }
    public static void cc(BufferedReader br, HashMap<String, Integer> map) throws IOException {
        String str;
        while ((str = br.readLine()) != null) {
            String[] split = str.split(",");
            String str1;
            if (split[4].contains("元")) {
                str1 = split[4].replace("元", "");
            } else {
                str1 = split[4];
            }
            int xz = (Integer.parseInt(str1.split("-")[1]) + Integer.parseInt(str1.split("-")[0])) / 2;
            if (split[1].contains("初中高")) {
                if (map.containsKey("java初中高级开发工程师")) {
                    int value = map.get("java初中高级开发工程师");
                    value = (value + xz) / 2;
                    map.put("java初中高级开发工程师", value);
                } else {
                    map.put("java初中高级开发工程师", xz);
                }
            } else if (split[1].contains("中高")) {
                if (map.containsKey("java中高级开发工程师")) {
                    int value = map.get("高级java开发工程师");
                    value = (value + xz) / 2;
                    map.put("java中高级开发工程师", value);
                } else {
                    map.put("java中高级开发工程师", xz);
                }
            } else {
                if (map.containsKey("java高级开发工程师")) {
                    int value = map.get("java高级开发工程师");
                    value = (value + xz) / 2;
                    map.put("java高级开发工程师", value);
                } else {
                    map.put("java高级开发工程师", xz);
                }
            }
        }
    }
}
